#pragma once

#include "d3dx9.h"
#include "d3d9.h"

#include "DAEFloat.h"
#include "DAETexture.h"

#include "util.h"
/**
* The Material class describes the material. It is based on the 
* obj material file format, but it can be extended to include
* custom Material properties.
* @author Koen Samyn
*/
class Material
{
public:
	/**
	* Constructs a new material object.
	* @param materialName the name for the material.
	*/
	Material(tstring materialName);
	/**
	* Destroys the material object.
	*/
	virtual ~Material(void);
	/**
	* Sets vertex skinning to true.
	*/
	void SetUseVertexSkinning(bool useVertexSkinning){
		m_UseVertexSkinning = useVertexSkinning;
	}
	/**
	* Returns true if vertex skinning is used.
	* @return true if vertex skinning is used, false otherwise.
	*/
	bool UsesVertexSkinning(){
		return m_UseVertexSkinning;
	}
	/**
	* Sets the shader to use for this material.
	* @param shaderName the name of the shader.
	*/
	void SetEffectFileName(wstring shader){m_EffectFileName = shader;}
	wstring GetEffectFileName(){return m_EffectFileName;}
	/**
	* Returns the material name for this material.
	*/
	tstring GetMaterialName() {return m_MaterialName;}
	/**
	* Returns the location for the diffuse texture (relative to the executable).
	* @return the location for the diffuse texture.
	*/
	tstring GetDiffuseTexture(){return m_DiffTexture;}
	/**
	* Sets the location for the diffuse texture.
	* @param diffTexture the new diffuse texture to use.
	*/
	void SetDiffuseTexture(tstring diffTexture);
	/**
	* Checks if a diffuse texture has been set. If true this diffuse texture should be used. If
	* false the material diffuse color should be used.
	* @return true if this material defines a diffuse texture, false otherwise.
	*/
	bool IsDiffuseTextureSet(){return m_DiffTextureSet;}

	/**
	* Returns the location for the specular texture (relative to the executable).
	* @return the location for the diffuse texture.
	*/
	tstring GetSpecularTexture(){return m_SpecularTexture;}
	/**
	* Sets the location for the specular texture.
	* @param specularTexture the new specular texture to use.
	*/
	void SetSpecularTexture(tstring specularTexture);
	/**
	* Checks if a specular texture has been set. If true this specular texture should be used. If
	* false the material specular color should be used.
	* @return true if this material defines a specular color, false otherwise.
	*/
	bool IsSpecularTextureSet(){return m_SpecularTextureSet;}

	/**
	* Returns the location for the specular texture (relative to the executable).
	* @return the location for the diffuse texture.
	*/
	tstring GetNormalMapTexture(){return m_NormalMapTexture;}
	/**
	* Sets the location for the specular texture.
	* @param specularTexture the new specular texture to use.
	*/
	void SetNormalMapTexture(tstring normalMapTexture);
	/**
	* Checks if a specular texture has been set. If true this specular texture should be used. If
	* false the material specular color should be used.
	* @return true if this material defines a specular color, false otherwise.
	*/
	bool IsNormalMapTextureSet(){return m_NormalMapTextureSet;}
	/**
	* Sets the ambient color.
	* @param ambient the ambient color to set.
	*/
	void SetAmbientColor(D3DXVECTOR3 ambient){m_Ambient = ambient;}
	/**
	* Gets the ambient color.
	* @return the ambient color.
	*/
	D3DXVECTOR3 GetAmbientColor(){return m_Ambient;}
	/**
	* Sets the specular color.
	* @param specular the specular color to set.
	*/
	void SetSpecularColor(D3DXVECTOR3 specular){m_Specular = specular;}
	/**
	* Gets the specular color.
	* @return the specular color.
	*/
	D3DXVECTOR3 GetSpecularColor(){return m_Specular;}

	/**
	* Sets the diffuse color.
	* @param diffuse the diffuse color to set.
	*/
	void SetDiffuseColor(D3DXVECTOR3 diffuse){m_Diffuse = diffuse;}
	/**
	* Gets the diffuse color.
	* @return the diffuse color.
	*/
	D3DXVECTOR3 GetDiffuseColor(){return m_Diffuse;}

	/**
	* Sets the alpha value of this material (default is 1).
	* @param alpha the alpha value for this material.
	*/
	void SetAlpha(float alpha){m_Alpha = alpha;}
	/**
	* Gets the alpha value for this material.
	* @return the alpha value.
	*/
	float GetAlpha(){return m_Alpha;}

	/**
	* Sets the shininess value for this material.
	* @param shininess the new shininess value.
	*/
	void SetShininess(float shininess){m_Shininess.x=shininess;}
	/**
	* Gets the shininess value for this material.
	* @return the shininess value.
	*/
	float GetShininess(){return m_Shininess.x;}
	/**
	* Gets a pointer to the Shininess DAEFloat object for 
	* use in a ShaderParameter.
	*/
	DAEFloat* GetShininessAsParameter(){return &m_Shininess;}
	/**
	* Gets the compiled direct x diffuse texture.
	* @return the Texture* to the diffuse texture.
	*/
	DAETexture* GetDiffuseDXTexture(){return m_DiffuseDXTex;}
	/**
	* Gets the compiled direct x specular texture.
	* @return the Texture* to the specular texture.
	*/
	DAETexture* GetSpecularDXTexture(){return m_SpecularDXTex;}
	/**
	* Gets the compiled direct x normal map texture.
	* @return the Texture* to the normal map texture.
	*/
	DAETexture* GetNormalMapDXTexture(){return m_NormalMapDXTex;}
 
	/**
	* Sets the name for this material.
	*/
	void SetName(tstring materialName){
		m_MaterialName = materialName;
	}
private:
	/**
	* The name of the shader to use.
	*/
	wstring m_EffectFileName;
	/**
	* The name for the material in the obj file.
	*/
	tstring m_MaterialName;
	/**
	* Indicates that vertex skinning should be used.
	*/ 
	bool m_UseVertexSkinning;
	/**
	* A string with the location of the diffuse texture.
	*/
	tstring m_DiffTexture;
	/**
	* boolean that indicates that the diffuse texture has been set.
	*/
	bool m_DiffTextureSet;
	/**
	* A string with the location of the specular texture.
	*/
	tstring m_SpecularTexture;
	/**
	* boolean that indicates that the specular texture has been set.
	*/
	bool m_SpecularTextureSet;
	/**
	* A string with the location of the normal map texture.
	*/
	tstring m_NormalMapTexture;
	/**
	* boolean that indicats that the normal map texture has been set.
	*/
	bool m_NormalMapTextureSet;
	/**
	* The alpha value of the material.
	*/
	float m_Alpha;
	/**
	* The shininess of the material. A specular map can be used instead.
	*/
	DAEFloat m_Shininess;
	/**
	* The ambient color for the material. Ignored in our engine
	*/
	D3DXVECTOR3 m_Ambient;
	/**
	* The diffuse color color for the material. Can be used if no texture is
	* defined.
	*/
	D3DXVECTOR3 m_Diffuse;
	/**
	* The specular color for the material. Can be used if no specular texture is
	* defined.
	*/
	D3DXVECTOR3 m_Specular;
	/**
	* The compile direct x diffuse texture.
	*/
	DAETexture *m_DiffuseDXTex;
	/**
	* The compiled direct x specular texture.
	*/
	DAETexture *m_SpecularDXTex;
	/**
	* The compiled direct x normal map texture.
	*/
	DAETexture *m_NormalMapDXTex;
};
